/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: syyyy
 * Date: 2025-08-11
 * Time: 17:42
 */
public class MyCircleQueue {
    public int[] elem;
    public int front;
    public int rear;
    //这里我用浪费一个空间来判满,就不定义size了

    public MyCircleQueue(int k){
        elem=new int[k+1  ];
    }

    public void enQueue(int val){
        if(isFull()){
            throw new FullQueueException();
        }
        elem[rear]=val;
        rear=(rear+1)% elem.length;
    }

    public int deQueue(){
        if(isEmpty()){
            throw new EmptyQueueException();
        }
        int val=elem[front];
        front=(front+1)% elem.length;
        return val;
    }

    public int Front(){
        if(isEmpty()){
            throw new EmptyQueueException();
        }
        return elem[front];
    }

    public int Rear(){
        if(isEmpty()){
            throw new EmptyQueueException();
        }
        int ret=(rear==0 ? rear=7 : rear-1);
        return elem[ret];
    }

    public boolean isFull(){
        return (rear+1)% elem.length==front;//不能写rear+1,如果rear==7,加一就越界了
    }

    public boolean isEmpty(){
        return rear==front;
    }
}
